<?php
require_once('includes/db.php');

$tableName='users';
$id = isset($_POST['id'])?$_POST['id']:0;//hidden field
if(isset($_FILES['e_avatar'])){
  $_FILES['avatar'] = $_FILES['e_avatar'];
  unset($_FILES['e_avatar']);
}
//print_r($_FILES);exit;
$data = upload($_FILES);//new image details and upload is function in function.php

if($data['flag'] == 1) {
  $_POST['avatar'] = $data['fileName'];
  ////////   THUMBNAIL /////////////
  ini_set('memory_limit', '-1');
// include image processing code
require_once('thumb/image.class.php');

$img = new Zubrag_image;
$img->max_x        = 80;
$img->max_y        = 60;
$img->GenerateThumbFile("uploads/$data[fileName]",
                         "uploads/thumbs_80_60/$data[fileName]");//700/50


$img = new Zubrag_image;
$img->max_x        = 120;
$img->max_y        = 90;
$img->GenerateThumbFile("uploads/$data[fileName]",
                         "uploads/thumbs_120_90/$data[fileName]");//700/50

$img = new Zubrag_image;
$img->max_x        = 200;
$img->max_y        = 150;
$img->GenerateThumbFile("uploads/$data[fileName]",
                         "uploads/thumbs_200_150/$data[fileName]");//700/50

}
  ////////////////////////////////////
  $oldAvatarName = $_POST['oldAvatarName'];
  unlink("uploads/$oldAvatarName");
  unlink("uploads/thumbs_200_150/$oldAvatarName");
  unlink("uploads/thumbs_120_90/$oldAvatarName");
  unlink("uploads/thumbs_80_60/$oldAvatarName");
    
  unset($_POST['oldAvatarName']);
  
  updateById($tableName, $_POST, $id );
  //$id = update('users',$_POST);
  //echo "Record Inserted on ID $id";

  header('location:all_users.php'); // it redirects to alluser page
  exit;

